package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.BaseData;
import com.cskaoyan.bean.bo.*;
import com.cskaoyan.bean.pojo.MallBrand;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.BrandCreateVo;
import com.cskaoyan.bean.vo.BrandUpdateVo;
import com.cskaoyan.service.BrandListService;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @Description:品牌制造商
 * @Author: chaohe@com.cskaoyan
 * @Date: 2021/7/9
 * @Time: 1:27
 */
@RestController
@RequestMapping("admin/brand")
public class BrandListController {

    @Autowired
    BrandListService brandListService;

    /**
     * @Author chaohe
     * @description: 品牌制造商的刷新
     * @Date 14:38 2021/7/10
     * url:   http://localhost:8083/admin/brand/list
     */
    @GetMapping("/list")
    @RequiresPermissions("admin:brand:list")
    public BaseRespVo list(BaseParmListBo baseParmListBo) {

        BaseData<MallBrand> baseData = brandListService.list(baseParmListBo);
        return BaseRespVo.ok(baseData);

    }

    /**
     * @Author chaohe
     * @description: 品牌制造商的新增
     * @Date 14:40 2021/7/10
     * url: http://localhost:8083/admin/brand/create
     */
    @RequestMapping("/create")
    @RequiresPermissions("admin:brand:create")
    public BaseRespVo create(@RequestBody BrandCreateBo brandCreateBo) {
        BrandCreateVo brandCreateVo = brandListService.create(brandCreateBo);
        return BaseRespVo.ok(brandCreateVo);
    }

    /**
     * @Author chaohe
     * @description: 品牌制造商的删除
     * @Date 14:41 2021/7/10
     * url: http://localhost:8083/admin/brand/delete
     */

    @PostMapping("/delete")
    @RequiresPermissions("admin:brand:delete")
    public BaseRespVo delete(@RequestBody BrandBaseBo brandBaseBo) {

        brandListService.delete(brandBaseBo);
        return BaseRespVo.ok();
    }

    /**
     * @Author chaohe
     * @description: 品牌制造商的更新
     * @Date 14:41 2021/7/10
     * url:   http://localhost:8083/admin/brand/update
     */

    @PostMapping("update")
    @RequiresPermissions("admin:brand:update")
    public BaseRespVo update(@RequestBody BrandUpdateBo brandUpdateBo) {

        if (brandUpdateBo.getFloorPrice() == null) {
            return BaseRespVo.fail1();
        }

        Double d = brandUpdateBo.getFloorPrice().doubleValue();
        if (d < 0) {

            return BaseRespVo.fail1();
            }
            BrandUpdateVo brandUpdateVo = brandListService.update(brandUpdateBo);
            return BaseRespVo.ok(brandUpdateVo);
        }

//        if (brandUpdateBo.getFloorPrice() != null && d >= 0) {
//
//            BrandUpdateVo brandUpdateVo = brandListService.update(brandUpdateBo);
//            return BaseRespVo.ok(brandUpdateVo);
//        }else {
//            return BaseRespVo.fail1();
//        }
//    }
//    }

}
